package com.alon.spring01.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpUtil;
import com.alon.spring01.common.model.Result;
import com.alon.spring01.service.InsuranceBaseInfoService;
import com.alon.spring01.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: spring01
 * @description: 保险控制器类
 * @author: yulongguang
 * @create: 2019-04-22 21:33
 **/
@RestController
@Slf4j
@RequestMapping("/insurance")
@Api("保险管理相关的api")
public class InsuranceBseInfoController {
    @Autowired
    private InsuranceBaseInfoService baseInfoService;

    @ApiOperation(value = "新增保险数据", notes = "新增保险数据")
    @PostMapping("/insertInsurance")
    public Result<?> insertInsurance(){
        try {
//            DateUtil.parseDate()

            baseInfoService.insertList();
            return ResultUtil.ok();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("新增保险数据出险异常 || e：{}",e.getMessage());
            return ResultUtil.error();
        }
    }
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/selectByPage")
    public Result<?> selectByPage(@ApiParam(name = "page", value = "页数") int page,
            @ApiParam(name = "pageSize", value = "分页大小") int pageSize) {

        return ResultUtil.ok(baseInfoService.findwithPage(page, pageSize));

    }

}
